<?php include_once "ra_global.php";
header("Content-Type:text/html;charset=utf-8");
//店长店员注册
if($_GET['add_user']){
	$res_add_user=insert_user_role($_GET['openid'],$_GET['tid'],$_GET['type'],$_GET['name'],$_GET['phone'],str_replace("'","&apos;",$_GET['address']));
	if($res_add_user) echo 'success';
	else echo 'error';
}
$aid=$_GET['aid'];
if ($aid) {
	 $activeProductSql = "SELECT cardnum,password FROM mae_admin_product_exchange_detail_log_virtual  WHERE detaillogid='".$aid."'";
	 $activeProductList = $db->ig2_query_select($activeProductSql);
	 foreach ($activeProductList as $key => $value) {
	 	echo "您的兑换码：".$activeProductList[$key]['cardnum']."<br>&nbsp;&nbsp;&nbsp;您的密码：".$activeProductList[$key]['password']."<br>";
	 }
	 //print_r($activeProductList);exit;
	 //echo "您的物品为：'".$activeProductList[0]['cardnum']."'<br>您的密码为'".$activeProductList[0]['password']."'";
}
//修改个人资料
if($_GET['update_user']){
	$value=array(
		'name'		=>$_GET['name'],
		'phone'		=>$_GET['phone'],
		'address'	=>str_replace("'","&apos;",$_GET['address']),
	);
	$db->ig2_update('mae_user',$value,'id='.$_GET['id']);
	echo 'success';
}
//兑换消费者礼包
if($_GET['admin_exchange']){
	if($_GET['number']>0){
		$shop=$db->ig2_want('mae_shop','id='.$_GET['shop_id']);
		$need_integral=$_GET['number']*80;
		$have_integral=$shop['quadratic'];
		if($have_integral<$need_integral){
			echo 'error';//积分不足
		}else{
			$db->ig2_query("BEGIN");
			$value=array(
				'id'			=>'',
				'account_id'	=>16621,
				'shop_id'		=>$shop['id'],
				'uid'			=>$_GET['uid'],
				'number'		=>$_GET['number'],
				'type'			=>$_GET['type'],
				'is_delivery'	=>0,
				'delivery_time'	=>0,
				'create_time'	=>time(),
			);
			$res1=$db->ig2_insert('mae_shop_admin_exchange_list',$value);
			$res2=$db->ig2_query('update mae_shop set quadratic=quadratic-'.$need_integral.' where id='.$shop['id']);
			if($res1 && $res2) {
				$db->ig2_query("COMMIT");
				echo 'success';//兑换成功
			}else{
				$db->ig2_query("ROLLBACK");
				echo 'error';//兑换错误
			}
		}
	}else{
		echo 'error';//兑换失败
	}
}
//查看兑换码
if($_GET['selvirtualinfo']){
	if($_GET['type']==1){
		$user_exchange_list=$db->ig2_want('mae_shop_user_exchange_list','id='.$_GET['id']);
		$prize_virtual=$db->ig2_want('mae_prize_virtual','id='.$user_exchange_list['virtual_id']);
		$prize=$db->ig2_want('mae_prize','id='.$prize_virtual['prize_id']);
		
		$res['type']=1;
		$res['cardnum']=$prize_virtual['cardnum'];
		$res['password']=$prize_virtual['password'];
		$res['describes']=$prize['describes'];
		$res['result']='success';
	}else if($_GET['type']==2){
		$award=$db->ig2_want('mae_award','id='.$_GET['id']);
		
		if(trim($award['jd_card'])){
			$prize=$db->ig2_want('mae_prize','id=1');
			$res['cardnum']=$award['jd_card'];
			$res['describes']=$prize['describes'];
		}else{
			$res['cardnum']='';
		}
		$res['type']=2;
		$res['password']=$award['code'];
		$res['result']='success';
	}else{
		$res['result']='error';
	}
	
	exit(json_encode($res));
}
//生成兑换清单
if($_GET['detailed_list']){
	$str='';$need=0;
	foreach($db->ig2_select('mae_prize','1') as $list){
		if($_GET['prize_'.$list['id']] > 0){
			$need_integral=$_GET['prize_'.$list['id']]*$list['need_integral'];
			$need+=$need_integral;
			$str.='
				<li>
					<span class="qdtext_1 qdtext">'.$list['name'].'</span>
					<span class="qdtext_2 qdtext">'.$_GET['prize_'.$list['id']].'</span>
					<span class="qdtext_3 qdtext">'.$need_integral.'</span>
				</li>
			';
		}
	}
	$str.='
		<div id="qdbox">
			<img id="qd_3" src="images/qd_3.png">
			<span class="qdbox_1 txt">'.$need.'</span>	
		</div>
	';
	$res['result']='success';
	$res['str']=$str;
	exit(json_encode($res));
}

function exchange_card($prize_arr,$uid,$need_integral,$name,$phone,$address){
	$db=new ig2sql();
	$user=$db->ig2_want('mae_user','id='.$uid);
	if(!$user || ($user && ($user['score']-$user['used_score'] < $_GET['need_integral']))){
		exit('error2');//用户不存在或用户可用积分小于本次兑换所用积分
	}else{
		$db->ig2_query("BEGIN");
		
		foreach($prize_arr as $k=>$v){
			$prize=$db->ig2_want('mae_prize','id='.$k);
			if($prize['is_virtual'] == 1){
				for($i=0;$i<$v;$i++){
					$prize_virtual=$db->ig2_want('mae_prize_virtual','prize_id='.$prize['id'].' and is_used=0');
					if(!$prize_virtual){
						$db->ig2_query("ROLLBACK");
						exit('error3');//没有可用虚拟商品兑换券
					}
					$value=array(
						'id'			=>'',
						'account_id'	=>16621,
						'uid'			=>$user['id'],
						'prize_id'		=>$prize['id'],
						'virtual_id'	=>$prize_virtual['id'],
						'create_time'	=>time(),
					);
					$id=$db->ig2_insert2('mae_shop_user_exchange_list',$value);
					if(!$id){
						$db->ig2_query("ROLLBACK");
						exchange_card($prize_arr,$uid,$need_integral,$name,$phone,$address);
						//exit('error4');//插入用户兑换记录出错
					}else{
						$prize_virtual=$db->ig2_want('mae_prize_virtual','id='.$prize_virtual['id']);
						if($prize_virtual['is_used'] == 1){
							$db->ig2_query("ROLLBACK");
							exchange_card($prize_arr,$uid,$need_integral,$name,$phone,$address);
							//exit('error5');//操作异常
						}else{
							$db->ig2_update('mae_prize_virtual',array('is_used'=>1),'id='.$prize_virtual['id']);
						}	
					}
				}
			}else{
				for($i=0;$i<$v;$i++){
					$value=array(
						'id'			=>'',
						'account_id'	=>0,
						'uid'			=>$user['id'],
						'prize_id'		=>$prize['id'],
						'name'			=>$name,
						'phone'			=>$phone,
						'address'		=>$address,
						'status'		=>0,
						'create_time'	=>time(),
					);
					$id=$db->ig2_insert2('mae_shop_user_exchange_list2',$value);
					if(!$id){
						$db->ig2_query("ROLLBACK");
						exchange_card($prize_arr,$uid,$need_integral,$name,$phone,$address);
						//exit('error4');//插入用户兑换记录出错
					}
				}
				$db->ig2_query('update mae_prize set stock=stock-'.$v.' where id='.$prize['id']);
			}
		}
		
		$res=$db->ig2_query('update mae_user set used_score=used_score+'.$need_integral.' where id='.$user['id']);
		if($res){
			$db->ig2_query("COMMIT");
			exit('success');	
		}else{
			$db->ig2_query("ROLLBACK");
			exit('error6');//修改个人积分出错
		}
	}
}
//用户兑换商品
if($_GET['exchange_card']){
	$stime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
	$etime=strtotime("$stime +1 month");//当月结束时间 时间戳
	$stime=strtotime($stime);//当月开始时间 时间戳
	$month_score=0;
	foreach($db->ig2_select('mae_shop_user_exchange_list','uid='.$_GET['uid'].' and create_time>="'.$stime.'" and create_time<"'.$etime.'"') as $list){
		$prize=$db->ig2_want('mae_prize','id='.$list['prize_id']);
		$month_score+=$prize['need_integral'];
	}
	foreach($db->ig2_select('mae_shop_user_exchange_list2','uid='.$_GET['uid'].' and create_time>="'.$stime.'" and create_time<"'.$etime.'"') as $list){
		$prize=$db->ig2_want('mae_prize','id='.$list['prize_id']);
		$month_score+=$prize['need_integral'];
	}
	if($month_score+$_GET['need_integral']>600){
		exit('error1');//用户兑换积分超出当月兑换积分上限
	}else{
		$prize_arr=array();
		foreach($db->ig2_select('mae_prize','1') as $list){
			if($_GET['prize_'.$list['id']] > 0){
				$prize_arr[$list['id']]=$_GET['prize_'.$list['id']];
			}
		}
		$result=exchange_card($prize_arr,$_GET['uid'],$_GET['need_integral'],$_GET['name'],$_GET['phone'],$_GET['address']);
		exit($result);
	}
}
//答题
if($_GET['sub_answer']){
	$user=$db->ig2_want('mae_user','id='.$_GET['uid']);
	$answer=$db->ig2_want('mae_answer','id='.$_GET['aid']);
	$role=$db->ig2_want('mae_role','uid='.$user['id'].' and is_delete=0');
	if($answer['bingo'] == 0){
		$res['status']='error';
	}else{
		$res['status']='correct';
		$db->ig2_update('mae_user',array('score'=>$user['score']+10),'id='.$user['id']);
		//$db->ig2_query('update mae_shop set quadratic=quadratic+10 where id='.$role['shop_id']);
	}
	$value=array(
		'id'			=>'',
		'uid'			=>$user['id'],
		'qid'			=>$answer['question_id'],
		'result'		=>$answer['bingo'],
		'create_time'	=>time(),
	);
	$db->ig2_insert('mea_user_answer_record',$value);
	if(trim($user['answer_ids'])){
		$answer_ids_arr=explode(',',$user['answer_ids']);
	}else{
		$answer_ids_arr=array();
	}
	array_push($answer_ids_arr,$_GET['qid']);
	$answer_ids_str=implode(',',$answer_ids_arr);
	$db->ig2_update('mae_user',array('answer_ids'=>$answer_ids_str),'id='.$user['id']);
	$res['result']='success';
	exit(json_encode($res));
}
//店长替换店员
if($_GET['del_user']){
	$user=$db->ig2_want('mae_user','id='.$_GET['id']);
//	$value=array(
//		'id'			=>$user['id'],
//		'account_id'	=>16621,
//		'openid'		=>$user['openid'],
//		'role_type'		=>$user['role_type'],
//		'sell_count'	=>$user['sell_count'],
//		'score'			=>$user['score'],
//		'used_score'	=>$user['used_score'],
//		'name'			=>$user['name'],
//		'phone'			=>$user['phone'],
//		'address'		=>$user['address'],
//		'answer_ids'	=>$user['answer_ids'],
//		'is_success'	=>$user['is_success'],
//		'success_time'	=>$user['success_time'],
//		'is_get'		=>$user['is_get'],
//		'get_time'		=>$user['get_time'],
//		'create_time'	=>$user['create_time'],
//	);

    $now = time();
//	$db->ig2_insert('mae_user_out',$value);
	$db->ig2_update('mae_role',array('is_delete'=>1,'delete_time'=>$now),'uid='.$user['id'].' and role_type!=1 and is_delete=0');
    $db->ig2_update('mae_user',array('is_delete'=>1,'delete_time'=>$now),'id='.$user['id'].' and role_type!=1 and is_delete=0');
	//$db->ig2_delete('mae_user','id='.$user['id']);
	echo 'success';
}
//查询是否超过没约兑换上限
if($_GET['monthly_limit']){
	$stime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
	$etime=strtotime("$stime +1 month");//当月结束时间 时间戳
	$stime=strtotime($stime);//当月开始时间 时间戳
	$month_score=0;
	foreach($db->ig2_select('mae_shop_user_exchange_list','uid='.$_GET['uid'].' and create_time>="'.$stime.'" and create_time<"'.$etime.'"') as $list){
		$prize=$db->ig2_want('mae_prize','id='.$list['prize_id']);
		$month_score+=$prize['need_integral'];
	}
	foreach($db->ig2_select('mae_shop_user_exchange_list2','uid='.$_GET['uid'].' and create_time>="'.$stime.'" and create_time<"'.$etime.'"') as $list){
		$prize=$db->ig2_want('mae_prize','id='.$list['prize_id']);
		$month_score+=$prize['need_integral'];
	}
	if($month_score+$_GET['need_integral']>600){
		echo 'yes';
	}else{
		echo 'no';
	}
}
//验证滚雪球卡券
if($_GET['ra_cheap_code']){
	$cheap_code=$db->ig2_want('mae_cheap_code','code='.$_GET['cheap_code']);
	if($cheap_code){
		if($cheap_code['count']<=$cheap_code['get_count']){
			echo 'error_1';//此代码使用已超过规定次数
		}else{
			$value=array('get_count'=>$cheap_code['get_count']+1);
			$db->ig2_update('mae_cheap_code',$value,'id='.$cheap_code['id']);
			$user=$db->ig2_want('mae_user,mae_role','mae_user.id=mae_role.uid and mae_role.is_delete=0 and mae_user.openid="'.$_GET['openid'].'"');
			$value=array(
				'id'			=>'',
				'account_id'	=>16621,
				'cheap_id'		=>$cheap_code['id'],
				'shop_id'		=>$user['shop_id'],
				'uid'			=>$user['uid'],
				'create_time'	=>time()
			);
			$db->ig2_insert('mae_cheap_code_log',$value);
			echo 'success';//代码验证成功
		}
	}else{
		echo 'error_2';//代码不存在
	}
}
//查询该店铺下还能注册几个店员
if($_GET['sel_user_surplu']){
	$roles=$db->ig2_select('mae_role','shop_id='.$_GET['shop_id'].' and role_type!=1 and is_delete=0');
	/* $shop_users=$db->ig2_select('mae_role','shop_id='.$_GET['shop_id'].' and role_type!=1 and is_delete=0 order by sort_id desc');
	$str='';
	foreach($shop_users as $list){
		$user=$db->ig2_want('mae_user','id='.$list['uid']);
		$stime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
		$etime=strtotime("$stime +1 month");//当月结束时间 时间戳
		$stime=strtotime($stime);//当月开始时间 时间戳
		
		$sql='SELECT count(*) as total FROM mae_sell WHERE uid = "'.$user['id'].'" and create_time >= "'.$stime.'" and create_time < "'.$etime.'"';
		$total=$db->ig2_query_select($sql);
		
		if($user['score']>=6000) $type='三';
		else if($user['score']>=2500 && $user['score']<=5999) $type='二';
		else if($user['score']<=2499) $type='一';
		
		$str.='
			<div id="li_'.$user['id'].'"><li>
				<img class="bt p3_1" src="images/p3_1.jpg" onclick="location.href=\'clerk.php?id='.$user['id'].'&source=admin\'">
				<img id="user_'.$user['id'].'" class="bt p3_2" src="images/p3_2.jpg">
				<span class="p2text p3text_1" >'.$user['name'].'</span>
				<span class="txt p3text_2" >'.$type.'级大师</span>
				<span class="p2text p3text_3" >现有积分：'.($user['score']-$user['used_score']).'</span>
				<span class="p2text p3text_4" >本月销量：'.$total[0]['total'].'</span>
			</li></div>
		';
	} */
	$res['result']='success';
	$res['count']=count($roles);
	//$res['str']=$str;
	exit(json_encode($res));
}
//意见箱
if($_GET['opnion']){
	$value=array(
		'id'			=>'',
		'uid'			=>$_GET['uid'],
		'content'		=>str_replace("'","&apos;",$_GET['content']),
		'is_delete'		=>0,
		'delete_time'	=>0,
		'create_time'	=>time(),
        'status' => 0
	);
	$id=$db->ig2_insert('mae_opnion',$value);
	if($id) echo 'success';
	else echo 'error';
}
//查看心愿单
if($_GET['see_wish_info']){
	$wish=$db->ig2_want('mae_wish_list','id='.$_GET['id']);
	if($wish){
		switch($wish['status']){
			case 1 : 
				$str='
					<div id="unrealized" class="bt">
						<img id="unrealizedbg" src="images/unrealizedbg.jpg">	
						<img id="unrealized_1" class="bt" src="'.(trim($wish['image'])?(file_exists('./logo/'.trim($wish['image']))?('./logo/'.trim($wish['image'])):'images/unrealized_1.jpg'):'images/unrealized_1.jpg').'">
						<div id="unrealizedbar" class="bt">
							<label id="unrealized_3" class="floats">【未实现】&nbsp;'.date('Y-m-d',$wish['create_time']).'</label>
							<label id="unrealized_4" class="floats">'.(trim($wish['content'])).'</label>
							<img id="unrealized_5" class="floats" src="images/transverse_line.jpg">
							<label id="unrealized_6" class="floats">心愿未实现？下月还有机会哦！</label>
							<img id="unrealized_2" class="floats" src="images/unrealized_2.jpg">
						</div>
						<script>
							document.getElementById("unrealized_2").addEventListener("touchstart", touchStartunrealized_2, false);
							document.getElementById("unrealized_2").addEventListener("touchend", touchEndunrealized_2, false);
							function touchStartunrealized_2(event){
								startX = event.touches[0].clientX;
								document.getElementById("unrealized_2").src="images/unrealized_2_h.jpg";	
							}
							function touchEndunrealized_2(event){
								endX = event.changedTouches[0].clientX;
								document.getElementById("unrealized_2").src="images/unrealized_2.jpg";
							}	
						</script>
					</div>
				';
				break;
			case 2 : 
				$str='
					<div id="Realized" class="bt">
						<img id="Realizedbg" src="images/Realizedbg.jpg">	
						<img id="Realized_1" class="bt" src="'.(trim($wish['image'])?(file_exists('./logo/'.trim($wish['image']))?('./logo/'.trim($wish['image'])):'images/Realized_1.jpg'):'images/Realized_1.jpg').'">
						<div id="Realizedbar" class="bt">
							<label id="Realized_4" class="floats">【已实现】&nbsp;'.date('Y-m-d',$wish['create_time']).'</label>
							<label id="Realized_5" class="floats">'.(trim($wish['content'])).'</label>
							<img id="Realized_7" class="floats" src="images/transverse_line.jpg">
							<label id="Realized_8" class="floats">我的评价</label>
							<div id="starbar" class="floats">
								<img id="star_1" class="bt star" src="images/star_1.png">
								<img id="star_2" class="bt star" src="images/star_1.png">
								<img id="star_3" class="bt star" src="images/star_1.png">
								<img id="star_4" class="bt star" src="images/star_1.png">
								<img id="star_5" class="bt star" src="images/star_1.png">
							</div>
							<textarea id="Realized_6" class="floats" maxlength="50"></textarea>
							<img id="Realized_2" class="floats" src="images/Realized_2.jpg">
							<script>
								document.getElementById("Realized_2").addEventListener("touchstart", touchStartRealized_2, false);
								document.getElementById("Realized_2").addEventListener("touchend", touchEndRealized_2, false);
								function touchStartRealized_2(event){
									startX = event.touches[0].clientX;
									document.getElementById("Realized_2").src="images/Realized_2_h.jpg";	
								}
								function touchEndRealized_2(event){
									endX = event.changedTouches[0].clientX;
									document.getElementById("Realized_2").src="images/Realized_2.jpg";
								}	
							</script>
							<img id="Realized_3" class="floats" src="images/Realized_3.jpg" onclick="subEvaluate(\''.$wish['id'].'\')">
							<script>
								document.getElementById("Realized_3").addEventListener("touchstart", touchStartRealized_3, false);
								document.getElementById("Realized_3").addEventListener("touchend", touchEndRealized_3, false);
								function touchStartRealized_3(event){
									startX = event.touches[0].clientX;
									document.getElementById("Realized_3").src="images/Realized_3_h.jpg";	
								}
								function touchEndRealized_3(event){
									endX = event.changedTouches[0].clientX;
									document.getElementById("Realized_3").src="images/Realized_3.jpg";
								}	
							</script>
						</div>
					</div>
				';
				break;
			case 3 : 
				$evaluate=$db->ig2_want('mae_wish_evaluate','wish_id='.$wish['id']);
				$star_str='';
				for($i=1;$i<=5;$i++){
					if($i > $evaluate['star']){
						$star_str.='<img id="stars_'.$i.'" class="bt stars" src="images/star_1.png">';
					}else{
						$star_str.='<img id="stars_'.$i.'" class="bt stars" src="images/star_2.png">';
					}
				}
				
				$str='
					<div id="evaluate" class="bt">
						<img id="evaluatebg" src="images/evaluatebg.jpg">	
						<img id="evaluate_1" class="bt" src="'.(trim($wish['image'])?(file_exists('./logo/'.trim($wish['image']))?('./logo/'.trim($wish['image'])):'images/evaluate_1.jpg'):'images/evaluate_1.jpg').'">
						<div id="evaluatebar" class="bt">
							<label id="evaluate_3" class="floats">【已评价】&nbsp;'.date('Y-m-d',$wish['create_time']).'</label>
							<label id="evaluate_4" class="floats">'.(trim($wish['content'])).'</label>
							<img id="evaluate_6" class="floats" src="images/transverse_line.jpg">
							<label id="evaluate_7" class="floats">我的评价</label>
							<div id="starsbar" class="floats">'.$star_str.'</div>
							<textarea id="evaluate_5" class="floats" readonly style=" border:none;">'.(trim($evaluate['content'])?$evaluate['content']:'-').'</textarea>
							<img id="evaluate_2" class="floats" src="images/evaluate_2.jpg">
							<script>
								document.getElementById("evaluate_2").addEventListener("touchstart", touchStartevaluate_2, false);
								document.getElementById("evaluate_2").addEventListener("touchend", touchEndevaluate_2, false);
								function touchStartevaluate_2(event){
									startX = event.touches[0].clientX;
									document.getElementById("evaluate_2").src="images/evaluate_2_h.jpg";	
								}
								function touchEndevaluate_2(event){
									endX = event.changedTouches[0].clientX;
									document.getElementById("evaluate_2").src="images/evaluate_2.jpg";
								}	
							</script>
						</div>
					</div>
				';
				break;
			default : break;
		}
		$res['result']='success';
		$res['str']=$str;;
	}else{
		$res['result']='error';
	}
	exit(json_encode($res));
}
//提交心愿单评价
if($_GET['sub_evaluate']){
	$wish=$db->ig2_want('mae_wish_list','id='.$_GET['wid']);
	$value=array(
		'id'			=>'',
		'wish_id'		=>$wish['id'],
		'content'		=>str_replace("'","&apos;",$_GET['content']),
		'star'			=>$_GET['star'],
		'create_time'	=>time(),
	);
	$result=$db->ig2_insert('mae_wish_evaluate',$value);
	if($result){
		$db->ig2_update('mae_wish_list',array('status'=>3),'id='.$wish['id']);
		$return['res']='success';
		
		$evaluate=$db->ig2_want('mae_wish_evaluate','wish_id='.$wish['id']);
		$star_str='';
		for($i=1;$i<=5;$i++){
			if($i > $evaluate['star']){
				$star_str.='<img id="stars_'.$i.'" class="bt stars" src="images/star_1.png">';
			}else{
				$star_str.='<img id="stars_'.$i.'" class="bt stars" src="images/star_2.png">';
			}
		}
		$str='
			<div id="evaluate" class="bt">
				<img id="evaluatebg" src="images/evaluatebg.jpg">	
				<img id="evaluate_1" class="bt" src="'.(trim($wish['image'])?(file_exists('./logo/'.trim($wish['image']))?('./logo/'.trim($wish['image'])):'images/evaluate_1.jpg'):'images/evaluate_1.jpg').'">
				<div id="evaluatebar" class="bt">
					<label id="evaluate_3" class="floats">【已评价】&nbsp;'.date('Y-m-d',$wish['create_time']).'</label>
					<label id="evaluate_4" class="floats">'.(trim($wish['content'])).'</label>
					<img id="evaluate_6" class="floats" src="images/transverse_line.jpg">
					<label id="evaluate_7" class="floats">我的评价</label>
					<div id="starsbar" class="floats">'.$star_str.'</div>
					<textarea id="evaluate_5" class="floats" readonly>'.(trim($evaluate['content'])?$evaluate['content']:'-').'</textarea>
					<img id="evaluate_2" class="floats" src="images/evaluate_2.jpg">
				</div>
			</div>
		';
		$return['str']=$str;
	}else{
		$return['res']='error';
	}
	exit(json_encode($return));
}
?>